/*
 * PurchaseProcess_BS.java
 *
 * Created on December 12, 2009, 10:22 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package Business;
import DAO.Purchase_DAO;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
/**
 *
 * @author mapxinh
 */
public class PurchaseProcess_BS  extends DAO.ConnectionDB{
    
    Connection conn= null;
    Purchase_DAO p= new Purchase_DAO();
    loadPurchase load;
    List<Purchase_BS> lstPur;
    loadPurchaseDetails loadpur;
    /**
     * Creates a new instance of PurchaseProcess_BS
     */
    private PurchaseProcess_BS() {
    }


    public loadPurchase viewPurchase() {
        load = new loadPurchase(p.loadPurchaseList());
        return load;
    }

    public loadPurchaseDetails viewPurchaseDetails(int pcID) throws SQLException{
        loadpur = new loadPurchaseDetails(p.loadPurchaseDetails(pcID));
        return loadpur;
    }
    
    public int addPurchase(Purchase_BS P)
    {
        int newId = p.addPurchase(P);
        if(newId != -1)
        {
            return newId;
        }
        else
        {
            //JOptionPane.showMessageDialog(null,"Purchase dosen't create successfull!", "Eror", JOptionPane.ERROR_MESSAGE);
            return -1;
        }
    }
    public void addPurchaseDetails(Purchase_BS P)
    {
        if(p.addPurchaseDetails(P) == true)
        {
             lstPur = p.loadPurchaseList();
             load.addPur(lstPur);
        }
    }

    
    private static PurchaseProcess_BS _pcp;
    public static PurchaseProcess_BS getPurchase() {
        if(_pcp == null) {
            _pcp = new PurchaseProcess_BS();
        }
        return _pcp;
    }

}

















